<!--预答辩审批-->
<template>
    <div class="con">
        <inner-breadcrumb v-model="pathKey" :path="path"></inner-breadcrumb>
        <div v-show="pathKey==='main'">
            <ConditionCard shadow="never" body-style="padding: 24px 24px 6px 24px;" @search="onSubmit" @reset="reset('queryForm')">
                <el-form ref="queryForm" label-suffix="：" :model="queryForm" label-position="right" label-width="120px">
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('label.schoolTerm')">
                                <CalendarSelect v-model="queryForm.yearTerm" @load-done="loadDone" :all="true"></CalendarSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.grade')">
                                <el-date-picker v-model="queryForm.grade" value-format="yyyy" :clearable="true" type="year" :placeholder="$t('paperBlindTrial.gredeTips')" style="width: 100%" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.college')">
                              <el-select
                                v-model="queryForm.academyId"
                                style="width: 100%;"
                                clearable
                                filterable
                                :placeholder="$t('common.text.all')"
                                v-clearreadonly
                              >
                                <el-option
                                    v-for="item in options.academyId"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                              </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('label.major')">
                                <MyMajor :faculty="queryForm.academyId" :filterable="true" :grade="queryForm.grade" v-model="queryForm.majorId" :clearable="true" v-clearreadonly> </MyMajor>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.trainingLevel')">
                                <DictSelect v-model="queryForm.eduLevel" :data="options.eduLevel" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.trainingCategory')">
                                <DictSelect v-model="queryForm.eduMode" :filterable="true" :data="options.eduMode" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('label.degreeCategory')">
                                <DictSelect v-model="queryForm.degreeType" :data="options.degreeType" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.formLearning')">
                                <DictSelect v-model="queryForm.studyForm" :data="options.studyForm" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('preDefense.auditState')">
                                <DictSelect v-model="queryForm.status" :data="options.status" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </ConditionCard>
            <el-card shadow="never" body-style="padding: 24px;">
              <h1 class="condition-title">{{$t('preDefense.preDefenseAuditTitle')}}</h1>
              <div class="edu-opertion-bar">
                <div class="float-left">
                  <KeywordInput v-model="queryForm.stuNoOrName" :placeholder="$t('achievementApply.tableIplaceholder')" @enter="onSubmit"></KeywordInput>
                </div>
                <div class="float-right">
                    <!-- 批量通过时默认意见通过，批量不通过时默认意见不通过 -->
                    <el-button @click="refuseApply" type="danger">{{$t('achievementApply.refuse')}}</el-button>
                    <el-button @click="passApply" type="primary">{{$t('message.pass')}}</el-button>
                </div>
              </div>
              <edu-table ref="tables" :url="tableApi" @selection-change="selectionChange" :orderFixed="true">
                <!-- <edu-table ref="tables" :data="data" show-overflow-tooltip :total="total" @selection-change="selectionChange" @page-change="pageChange"> -->
                <el-table-column :min-width="item.width" v-for="item in label" :key="item.props" :label="item.label"
                                 :prop="item.props" :fixed="item.fixed" show-overflow-tooltip></el-table-column>
                <el-table-column :min-width="80" :label="$t('preDefense.auditState')" show-overflow-tooltip fixed="right">
                  <template slot-scope="scope">
                    <el-tag v-for="item in options.status" v-if="scope.row.status===item.value" :key="item.value"
                            :type="item.type">{{item.label}}
                    </el-tag>
                  </template>
                </el-table-column>
                <el-table-column width="120px" :label="$t('nonPublicCourseOpen.operation')" fixed="right">
                  <template slot-scope="scope">
                    <div class="con_btns" @click.stop="">
                      <el-button type="text" v-if="scope.row.status==='SUBMIT'" @click="audit('status',scope.row)">{{$t('common.btn.approve')}}</el-button>
                      <el-button type="text" @click="audit('viewDetail', scope.row)">{{$t('message.Look')}}</el-button>
                      <el-button type="text" style="color:#ff5d0a" v-if="(scope.row.status && scope.row.status !== 'UNPASS') && !scope.row.examResult" @click="revokeFunc(scope.row)">{{$t('preDefense.revokeLabel')}}</el-button>
                    </div>
                  </template>
                  </el-table-column>
              </edu-table>
            </el-card>
        </div>
        <!-- 申请审批 -->
        <preDefenseAudit v-if="pathKey==='preDefenseAudit'" :options="options" :currentType="currentType" :row="selectRow" @emit:back="backFunc"></preDefenseAudit>
    </div>
</template>

<script>
import { applyList, applyTableList,auditReject } from "common/src/api/preDefense";
import MyMajor from "common/src/views/administrator/undergraduateTutor/component/MyMajor";
import preDefenseAudit from './preDefenseAudit';
import commonMixins from 'common/src/views/practiceManagement/commonMixins';
import { queryDic } from 'common/src/api/dictionary';
import { throughBatch, rejectBatch } from "common/src/api/studentRegister";
export default {
    components: {
        MyMajor,
        preDefenseAudit
    },
    mixins: [commonMixins],
    props: {},
    data() {
        return {
            tableApi: applyTableList,
            dialogFlag: false,
            objs: {
                ids: '',
                editFlag: false
            },
            yearTerms: '',
            queryForm: {
              yearTerm: '', // 学年学期
              grade: '', // 年级
              academyId: '', // 学院
              majorId: '', // 专业
              eduLevel: '', // 培养层次
              eduMode: '', // 培养类别
              degreeType: '', // 学位类别
              studyForm: '', // 学习形式
              status: '', // 审批状态
              stuNoOrName: ''
            },
            page: {
              pageNum_: 1,
              pageSize_: 20
            },
            label: [
              {label: this.$t('label.stuCode'), props: 'stuNo', width: 100, fixed: "left"},
              {label: this.$t('label.stuName'), props: 'stuName', width: 90, fixed: "left"},
              {label: this.$t('label.grade'), props: 'grade', width: 60},
              {label: this.$t('label.schoolTerm'), props: 'yearTermI18n', width: 180},
              {label: this.$t('label.college'), props: 'academyName', width: 160},
              {label: this.$t('label.major'), props: 'majorName', width: 160},
              {label: this.$t('label.trainingLevel'), props: 'eduLevelI18n', width: 120},
              {label: this.$t('label.trainingCategory'), props: 'eduModeI18n', width: 150},
              {label: this.$t('label.degreeCategory'), props: 'degreeTypeI18n', width: 150},
              {label: this.$t('label.formLearning'), props: 'studyFormI18n', width: 150},
            ],
            data: [],
            options: {
              academyId: [], // 学院
              status: [
                { label: this.$t('message.checking'), value: 'SUBMIT', type: '' },
                { label: this.$t('message.pass'), value: 'PASS', type: 'success' },
                { label: this.$t('achievementApply.refuse'), value: 'UNPASS', type: 'danger' },
              ],
              eduLevel: [], // 培养层次
              eduMode: [], // 培养类别
              degreeType: [], // 学位类型
              studyForm: [], // 学习形式
              majorId: [],
              direction: [] // 研究方向
            },
            pathKey: 'main',
            path: {
              label: this.$t('preDefense.preDefenseAuditTitle'),
              key: 'main',
              disable: false,
              children: [
                { label: this.$t('message.detail'), key: 'preDefenseAudit', disable: true, }
              ]
            },
            selectRow: {},
            selection: [],
            form: {
              auditRemark: "",
            },
            currentType: ''
        };
    },
    computed: {

    },
    created() {

    },
    mounted() {
        let param = {
          X_YX: 'academyId', // 学院
          // X_PYCC: 'eduLevel', // 培养层次
          X_PYLB: 'eduMode', // 培养类别
          X_XWLX: 'degreeType', // 学位类型
          K_XXXS: 'studyForm', // 学习形式
          G_ZY: 'majorId', // 专业:
          X_YJFX: "direction" // 研究方向
        };
        this.initOptions(param);
        this.getEdulevel();
    },
    methods: {
        getEdulevel() { // val: {  X_PYCC: 'trainingLevel',   G_ZY: 'profession'} // 专业
          const data = {
            lang: this.$store.getters.language || 'cn',
            type: 'allChild',
            keys: ['X_PYCC']
          };
          return new Promise((resolve, reject) => {
              queryDic(data).then(res => {
                  if (res.code === 200) {
                    this._fill('eduLevel', res.data['X_PYCC']);
                    this.options.eduLevel = this.options.eduLevel.filter(v => v.value === '4' || v.value === '6');
                  }
                  resolve(this.options);
              }).catch((err) => {
                  reject(err);
              });
          });
        },
        onSubmit() { // 筛选
          this.$refs.tables.pageNum = 1;
          //查询关键字和筛选条件独立
          let param = {};
          if (this.queryForm.stuNoOrName) {
            param = {stuNoOrName:this.queryForm.stuNoOrName.trim()};
          }else{
            param = _.cloneDeep(this.queryForm);
            param.stuNoOrName = '';
          }
          this.$refs.tables.search(param);
        },
        audit(type, row) { // 审批
          this.pathKey = 'preDefenseAudit';
          this.currentType = type;
          this.selectRow = row;
        },
        // 撤回方法
        revokeFunc(row) {
            this.$confirm(this.$t('preDefense.revokeTips'), this.$t('preDefense.tipsTitle'), {
                confirmButtonText: this.$t('message.confirm'),
                cancelButtonText: this.$t('message.cancel'),
                type: 'warning'
            }).then(() => {
                let param = [row.id];
                auditReject(param).then(res=>{
                    if (res.code === 200) {
                        this.$message.success(this.$t('course.operateSuccess'));
                        this.onSubmit();
                    }
                });
            });
        },
        reset() {  // 重置
          for (const key in this.queryForm) {
            if (key !== 'yearTerm') {
              this.queryForm[key] = '';
            }
          }
          this.queryForm.yearTerm = this.yearTerms;
          this.onSubmit();
        },
        pageChange(val) { // 分页切换功能
          [this.page.pageNum_, this.page.pageSize_] = [val.pageNum, val.pageSize];
          this.onSubmit();
        },
        loadDone() { // 页面加载时保存学期学年
          this.yearTerms = this.queryForm.yearTerm;
          this.onSubmit();
        },
        search() {
          this.queryForm.stuNoOrName = this.queryForm.stuNoOrName.trim();
          this.onSubmit();
        },
        selectionChange(selection) {
          this.selection = selection
        },
        // 通过申请
        passApply() {
          if (!this.isAudit()) {
            return;
          }
          this.$confirm(this.$t('preDefense.passListInfo'), this.$t('achievementApply.tipsTitle'), {
            confirmButtonText: this.$t('message.confirm'),
            cancelButtonText: this.$t('message.cancel'),
            type: 'warning'
          }).then(() => {
            let data = this.selection.map(r => {
              return {
                no: r.workFlowId,
                content: '同意'
              };
            });
            throughBatch(data).then(res => {
              if (res.code == 200) {
                this.$message({
                    type: "success",
                    message: this.$t('preDefense.passList')
                });
                this.onSubmit();
              }
            });
          });
        },
        //批量审批拒绝
        refuseApply() {
          if (!this.isAudit()) {
            return;
          }
          this.$confirm(this.$t('preDefense.refuseListInfo'), this.$t('achievementApply.tipsTitle'), {
            confirmButtonText: this.$t('message.confirm'),
            cancelButtonText: this.$t('message.cancel'),
            type: 'warning'
          }).then(() => {
            let data = this.selection.map(r => {
                return {
                    no: r.workFlowId,
                    content: '不同意'
                };
            });
            rejectBatch(data).then(res => {
                if (res.code == 200) {
                    this.$message({
                        type: "success",
                        message: this.$t('preDefense.refuseList')
                    });
                    this.onSubmit();
                }
            });
          });
        },
        backFunc () {
          this.pathKey = 'main';
          this.onSubmit();
        },
        // 是否能审核判断
        isAudit () {
          if (!this.selection || this.selection.length === 0) {
            this.$message.warning(this.$t('preDefense.checkAuditList'));
            return false;
          }
          // 未审核的记录
          let submitList = this.selection.filter(v => v.status==='SUBMIT');
          if (submitList.length !== this.selection.length) {
            this.$message.warning(this.$t('preDefense.notAuditAgainList'));
            return false;
          }
          return true;
        }
    }
};
</script>

<style scoped lang="scss">
.condition-title {
  color: #2b3b4e;
  font-size: 18px;
  line-height: 24px;
  font-weight: bold;
}
</style>

